//
//  WebViewErrorView.swift
//  Lease_IOS
//
//  Created by Mr.wang on 2019/1/21.
//  Copyright © 2019 Mr.wang. All rights reserved.
//

import UIKit

class WebViewErrorView: UIView {

    let contentLabel = UILabel()
    
    override init(frame: CGRect) {
        super.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 250))
        
        contentLabel.textAlignment = .center
        contentLabel.font = UIFont.systemFont(ofSize: 15)
        contentLabel.textColor = UIColor.init(white: 0.5, alpha: 1)
        contentLabel.numberOfLines = 0
        addSubview(contentLabel)
        contentLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.top.equalTo(self.snp.centerY).offset(20)
        }
    }
    
    func setActivity(success: Bool, isReachable: Bool) {
        self.isHidden = success
        var text = ""
        if !isReachable {
            text = "网页加载失败\n请检查网络设置后下拉重试".localized
        } else if !success {
            text = "找不到服务器\n请确认链接地址是否正确".localized
        }
        contentLabel.text = text
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
